﻿@{
    Layout = null;

}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui-v2.6.8/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="valID" id="valID" lay-verify="required" lay-reqtext="组织ID是必填项，岂能为空？" placeholder="请输入组织ID" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">字典值</label>
            <div class="layui-input-block">
                <input type="text" name="valName" id="valName" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">字典类别</label>
            <div class="layui-input-block">
                <select name="keyID" id="keyID" lay-verify="required">
                    <option value="">全部</option>
                    <option value="1">学历</option>
                    <option value="2">学位</option>
                    <option value="3">职业</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">拼音码</label>
            <div class="layui-input-block">
                <input type="text" name="firstPY" id="firstPY" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">显示顺序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" id="sort" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" name="remark" id="remark" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>


    <script src="~/layui-v2.6.8/layui-v2.6.8/layui/layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

    <script>

        //（4） 前端：浏览器请求服务器的时候，要带上JWT
        $.ajaxSetup({
            beforeSend: function (xhr) {
                if (localStorage.getItem("token") !== null) {
                    //（4） 前端：浏览器请求服务器的时候，要带上JWT
                    xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem("token"));
                }
            }
        });

        layui.use('form', function () {
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function (data) {
                $.ajax({
                    url: 'https://localhost:44398/api/DicAPI/Uep',
                    type: 'post',
                    data: data.field,
                    success: function (d) {
                        console.log(d);
                        if (d > 0) {
                            layer.msg("修改成功", function () {
                                parent.location.href = "/DictWeb/Index";
                            })
                        } else {
                            layer.msg("修改失败");
                            return;
                        }
                    }
                })
                return false;
            });
            //表单取值
            layui.$('#LAY-component-form-getval').on('click', function () {
                var data = form.val('example');
                alert(JSON.stringify(data));
            });
            //预编辑函数反填数据
            $(function () {

                $.ajax({
                    url: "https://localhost:44398/api/DicAPI/Fan?id= "+@ViewBag.id,
                    type: "get",
                    success: function (d) {

                        $("#valID").val(@ViewBag.id);
                        $("#valName").val(d.data.valName);
                        $("#keyID").val(d.data.keyID);
                        $("#firstPY").val(d.data.firstPY);
                        $("#sort").val(d.data.sort);
                        $("#remark").val(d.data.remark);
                    }
                })
            })
        });
    </script>

</body>
</html>
